package com.koron.css2.serviceManage.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.serviceManage.bean.BusinessAreaBean;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.mapper.BusinessAreaMapper;
import com.koron.css2.serviceManage.queryBean.BusinessAreaQueryBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import com.mysql.cj.util.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

/**
 * 营业区域，编辑初始化
 */
public class BusinessAreaQuery implements ServerInterface {
	
private static Logger logger = LogManager.getLogger(BusinessAreaQuery.class);
	
	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {

		@SuppressWarnings("rawtypes")
		MessageBean<BusinessAreaBean> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", BusinessAreaBean.class);

		try {
			BusinessAreaQueryBean bean = JsonUtils.objectToPojo(req.getData(), BusinessAreaQueryBean.class);
			BusinessAreaMapper mapper = factory.getMapper(BusinessAreaMapper.class);
			if (StringUtils.isNullOrEmpty(bean.getId())) {
				return MessageBean.create(Constant.ILLEGAL_PARAMETER, "id为空", void.class);
			}
			BusinessAreaBean businessAreaBean = mapper.findBusinessAreaInfoById(bean.getId());
			info.setData(businessAreaBean);
		} catch (Exception e) {
			info.setCode(Constant.MESSAGE_INT_FAIL);
			info.setDescription(e.getMessage());
			logger.error(e.getMessage(), e);
		}
		return info;
	}
}
